package com.example.zm_fanjiantao.web.controller;

import com.example.zm_fanjiantao.web.model.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api")
@RestController
public class RequestApi {
    @Resource
    private HttpServletRequest request;

    @PostMapping("/save")
    public User save(User user){
        return user;
    }
    @PostMapping("/save/json")
    public User saveJson(@RequestBody User  user){
        return user;
    }

    @GetMapping("/getuser")
    public User getUser(User user){
        return user;
    }
    @GetMapping("/getuser/{name}") //获取path参数
    public User getUserName(@PathVariable String name){
        User user = new User();
        user.setName(name);
        return user;
    }
    @GetMapping("/getParam") //获取query 参数
    public User getParams(@RequestParam String name){
        User user = new User();
        user.setName(name);
        return user;
    }

    @GetMapping("/getRequest")
    public User getRequest(){
        String name= request.getParameter("name");
        //获取的是字符串 需要转成整形
//        int sex = Integer.valueOf(request.getParameter("sex"));
        User user = new User();
        user.setName(name);
        return user;
    }
}
